import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  Post,
  Query,
} from '@nestjs/common';
import { FavoriteService } from './favorite.service';
import { CreateFavoriteDto } from './dto/create-favorite.dto';
import { QueryFavoriteDto } from './dto/query-favorite.dto';
import { RequireLogin, UserInfo } from 'src/custom.decorator';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiBearerAuth,
  ApiParam,
} from '@nestjs/swagger';

@ApiTags('收藏管理')
@ApiBearerAuth()
@Controller('favorite')
@RequireLogin()
export class FavoriteController {
  constructor(private readonly favoriteService: FavoriteService) {}

  @Post()
  @ApiOperation({ summary: '收藏商品' })
  @ApiResponse({ status: 201, description: '收藏成功' })
  async create(
    @Body() createFavoriteDto: CreateFavoriteDto,
    @UserInfo('userId') userId: number,
  ) {
    return await this.favoriteService.create(createFavoriteDto, userId);
  }

  @Get()
  @ApiOperation({ summary: '查询收藏列表' })
  async findAll(
    @Query() queryFavoriteDto: QueryFavoriteDto,
    @UserInfo('userId') userId: number,
  ) {
    return await this.favoriteService.findAll(queryFavoriteDto, userId);
  }

  @Delete(':id')
  @ApiOperation({ summary: '取消收藏' })
  @ApiParam({ name: 'id', description: '商品ID' })
  @ApiResponse({ status: 200, description: '取消成功' })
  async remove(@Param('id') id: string, @UserInfo('userId') userId: number) {
    return await this.favoriteService.remove(+id, userId);
  }
}
